<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>tl-spb-blog-后台添加配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script src="../../lib/axios.js"></script>
    <script src="../../lib/layui/layui.js" v="layui" e="layui"></script>
    <link rel="stylesheet" type="text/css" href="../../lib/layui/css/layui.css" />
</head>
<style>
    input {
        color: darkorchid;
        font-weight: 700;
    }
</style>
<body>

    <div class="layui-form" lay-filter="tl-ops-web-page-proxy-form" id="tl-ops-web-page-proxy-form" style="padding: 20px 20px 0 0;">
        <div class="layui-form-item" style="display: none;">
            <label class="layui-form-label">ID</label>
            <div class="layui-input-block">
                <input type="text" name="id" id="id" placeholder="请输入ID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="tl-ops-web-page-proxy-form-api-view"></div>
        <script id="tl-ops-web-page-proxy-form-api-tpl" type="text/html">
            {{#  if(d.length === 0) { }}
            <label class="layui-form-label">API规则</label>
            <div class="layui-input-block">
                <p style="line-height: 37px;">暂无API规则</p>
            </div>
            {{#  } else { }}
            <label class="layui-form-label">API规则</label>
            <div class="layui-input-block">
                <select name="api">
                    <option value="">请选择API规则</option>
                {{#  layui.each(d, function(index, api){ }}
                    <option value="{{api.url}}">{{api.host}}{{api.url}}</option>
                {{#  }); }}
                </select> 
            </div>
            {{#  } }}
        </script>

        <div class="layui-form-item">
            <label class="layui-form-label">资源路径</label>
            <div class="layui-input-block">
                <input type="text" name="path" id="path" maxlength="100" placeholder="请输入资源路径" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="tl-ops-web-page-proxy-form-submit" id="tl-ops-web-page-proxy-form-submit" value="确认">
        </div>
    </div>

    <script src="../../lib/tl_ops_web_comm.js"></script>
    <script>
        layui.use(['laytpl', 'form', 'layedit'], async function(){
            const _form_btn_id_name = "tl-ops-web-page-proxy-form-submit";
            const _form_id_name = "tl-ops-web-page-proxy-form";

            const _form_select_view_id_name = "tl-ops-web-page-proxy-form-api-view";
            const _form_select_tlp_id_name = "tl-ops-web-page-proxy-form-api-tpl";
            
            window.$ = layui.$;
            window.form = layui.form;
            window.laytpl = layui.laytpl;
            window.layedit = layui.layedit;

            let api_list = []
            let res = await axios.get("/tlops/balance/api/list");
            res = res.data;
            if(res.code === 0){
                let rule = res.data.tl_ops_balance_api_rule        
                api_list = res.data.tl_ops_balance_api_list[rule];
            }

            //渲染select
            laytpl(document.getElementById(_form_select_tlp_id_name).innerHTML).render((()=>{
                return api_list;
            })(), (html)=>{
                document.getElementById(_form_select_view_id_name).innerHTML = html;
            });

            form.render()

            window.tl_ops_web_page_proxy_form_render = function(data){
                form.val(_form_id_name, Object.assign(form.val(_form_id_name), data))
                form.render()
            }

            form.render()
        });
    </script>
</body>

</html>